package com.sevenGroup.pawnshop.Utils;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

public class UploadImage {
    public static String uploadImage(String name, String bucketName, InputStream is){
        String endpoint = "https://oss-cn-chengdu.aliyuncs.com";
        String accessKeyId = "LTAI5tSi9KozV3JL9jkusLrG";
        String accessKeySecret = "qSEOmCGsg78Iz1KhYZVN3IJLJoZqp2";
        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
        String url = null;
        try {
            ossClient.putObject(bucketName, name, is);
            url = "http://"+bucketName+".oss-cn-chengdu.aliyuncs.com/"+name;
        }finally {
            if (ossClient!=null){
                ossClient.shutdown();
            }
        }
        return url;
    }

}
